package com.coco.bargain.controller;

import com.coco.bargain.pojo.TbBargainGoods;
import com.coco.bargain.service.BargainGoodsService;
import com.coco.bargain.vo.BargainGoodsVo;
import com.coco.bargain.vo.GoodsSearchVo;
import com.coco.common.result.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/7/21 20:04
 */
@RestController
@RequestMapping("/bargain/goods")
public class BargainGoodsController {

    @Autowired
    private BargainGoodsService bargainGoodsService;

    /**
     * 列表 模糊 分页
     *
     * @param searchVo
     * @return
     */
    @PostMapping("/findByStatusAndName")
    public ResultData findByStatusAndName(@RequestBody GoodsSearchVo searchVo) {
        return bargainGoodsService.findByStatusAndName(searchVo);
    }

    /**
     * id逻辑删除
     *
     * @param id
     */
    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable Long id) {
        try {
            bargainGoodsService.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 修改状态
     *
     * @param id
     * @param status
     */
    @PutMapping("/updateStatus/{id}/{status}")
    public void updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        try {
            bargainGoodsService.updateStatus(id, status);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询单条
     *
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public TbBargainGoods findById(@PathVariable("id") Long id) {
        return bargainGoodsService.findById(id);
    }

    /**
     * 根据id修改
     *
     * @param bargainGoods
     */
    @PutMapping("/updateById")
    public void updateById(@RequestBody TbBargainGoods bargainGoods){
        bargainGoodsService.updateById(bargainGoods);
    }

    /**
     * 添加
     * @param tbBargainGoods
     */
    @PostMapping("/addToTbBargainGoods")
    public void addToTbBargainGoods(@RequestBody TbBargainGoods tbBargainGoods){
        try {
            bargainGoodsService.addToTbBargainGoods(tbBargainGoods);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 添加砍价商品 spu+sku
     * @author HanSama
     * @date 2021/7/22 18:52
     */
    @PostMapping("/addTbBargainGoods")
    public void addTbBargainGoods(@RequestBody BargainGoodsVo bargainGoodsVo){
        try {
            bargainGoodsService.addTbBargainGoods(bargainGoodsVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过spuID获取相关sku 并全部发返回
     * @author HanSama
     * @date 2021/7/22 19:43
     * @param id
     * @return com.coco.bargain.vo.BargainGoodsVo
     */
    @GetMapping("/findOne/{id}")
    public BargainGoodsVo findOne(@PathVariable("id") Long id){
        return bargainGoodsService.findOne(id);
    }

    /**
     * 修改spu和其sku
     * @author HanSama
     * @date 2021/7/22 19:44
     */
    @PostMapping("/updateBargainGoods")
    public void updateBargainGoods(@RequestBody BargainGoodsVo bargainGoodsVo){
        try {
            bargainGoodsService.updateBargainGoods(bargainGoodsVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
